import 'package:flutter/material.dart';

class YKStateFullController {

  YKStateFullWidget? _widget;

  void setState({void Function()? callBack}) {
    _widget?._setState(callBack: callBack);
  }

  YKStateFullController();
}

class YKStateFullWidgetDelegate {

  void Function()? disposeCallBack;

  void Function()? reassembleCallBack;

  void Function()? initStateCallBack;

  void Function(Widget oldwidget)? didUpdateWidgetCallBack;

  void Function()? deactivateCallBack;

  void Function()? didChangeDependenciesCallBack;

  void Function()? activateCallBack;

  YKStateFullWidgetDelegate({
    this.disposeCallBack,
    this.reassembleCallBack,
    this.initStateCallBack,
    this.didUpdateWidgetCallBack,
    this.deactivateCallBack,
    this.didChangeDependenciesCallBack,
    this.activateCallBack,
  });
}

class YKStateFullWidget extends StatefulWidget {

  final Widget Function(BuildContext context) widegtBuilder;

  YKStateFullController? _controller;

  YKStateFullWidgetDelegate? delegate;

  _YKStateFullWidgetState? _state;

  YKStateFullWidget({super.key, required this.widegtBuilder,
    this.delegate,
    YKStateFullController? controller
  }) {
    _controller = controller;
    _controller?._widget = this;

    _state = _YKStateFullWidgetState();
  }


  @override
  State<YKStateFullWidget> createState() => _state ?? _YKStateFullWidgetState();

  _setState({void Function()? callBack}) {
    _state?.setState(() {
      callBack?.call();
    });
  }
}

class _YKStateFullWidgetState extends State<YKStateFullWidget> {

  @override
  void initState() {
    widget.delegate?.initStateCallBack?.call();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return widget.widegtBuilder(context);
  }

  @override
  void didUpdateWidget(YKStateFullWidget oldWidget) {
    widget.delegate?.didUpdateWidgetCallBack?.call(oldWidget);
    super.didUpdateWidget(oldWidget);
  }

  @override
  void deactivate() {
    widget.delegate?.deactivateCallBack?.call();
    super.deactivate();
  }

  @override
  void dispose() {
    widget.delegate?.disposeCallBack?.call();
    super.dispose();
  }

  @override
  void reassemble() {
    widget.delegate?.reassembleCallBack?.call();
    super.reassemble();
  }

  @override
  void didChangeDependencies() {
    widget.delegate?.didChangeDependenciesCallBack?.call();
    super.didChangeDependencies();
  }

  void activate() {
    widget.delegate?.activateCallBack?.call();
    super.activate();
  }
}